package com.swyc.osschat.Test.LambdaTest.Controller;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

import com.google.common.collect.Lists;
import com.swyc.osschat.Test.LambdaTest.Bean.Student;
import com.swyc.osschat.Test.LambdaTest.IService.LambdaTestStydent;

/**
 * @author zhaol@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/8/12 10:17
 */
public class TestCaseLambdaTwo {
    public static List<List<Student>> fromFamly(LambdaTestStydent test){
        List<Student> student = test.uodateAge();
        List<List<Student>> resultStident = Lists.newArrayList();
        Map<String, List<Student>> allStudentMap = student.stream().collect(Collectors.groupingBy(Student::getSex));
        List<Student> manList = allStudentMap.get("1");
        Map<Integer,Student> womanMap = allStudentMap.get("2").stream().collect(Collectors.toMap(r->r.getId(),r->r,(v1,v2)->v2));
        manList.forEach(e->{
            List<Student> famly = Lists.newArrayList();
            famly.add(e);
            Student student1 = womanMap.get(e.getSpouse());
            int v = Objects.nonNull(student1)?student1.getSpouse():0;
            UnaryOperator<Boolean> unaryOperator = uglily -> famlyCheck(e.getId(),v);
            Boolean apply = unaryOperator.apply(checkIsExute(student1));
            if (apply){
                famly.add(student1);
            }
            resultStident.add(famly);
        });
        return resultStident;
    }

    public static void main(String[] args) {
        List<Student> student = Student.generateData();
        fromFamly(()->student);
        System.out.println("sssdsada");
    }

    public static boolean famlyCheck(int a,int b){
        if (a!=b){
            return false;
        }
        return true;
    }

    public static boolean checkIsExute(Student s){
        return Objects.nonNull(s);
    }
}
